package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.caelum.vraptor.interceptor.download.InputStreamDownload;
import br.com.vti.sisp_sicrim.antigo.model.SicCadnovo;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela
 * Scrpbe04Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Scrpbe04Report {
	private String dtini;
	private int jcont;
	private int jcont1;
	private String dataCorrente;
	private String datini;
	private String datfim;
	private String nroPagina;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	SicCadnovo sicCadnovoView = new SicCadnovo(); // Classes includes

	public Scrpbe04Report() throws JRException, ParseException {
		inicializar();
	}

	public Scrpbe04Report(Sessao sessao) throws JRException, ParseException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException, ParseException {
		report = new Relatorios();
		dtini = "";
		jcont = 0;
		jcont1 = 0;
		datini = "";
		datfim = "";
		dataCorrente = new SimpleDateFormat("dd/MM/yyyy").format(Calendar.getInstance().getTime()); // *DATE
		report.setNumeroRel(1, "C");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 2, "lit_1_2", "C", "", "  ");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 3);
			{
				report.adicionaCampo(1, 62, "lit_1_62", "C", "", "* GEJUSPC - GERENCIA DA JUSTICA, SEGURANCA PUBLICA E CIDADANIA");
				report.adicionaCampo(110, 8, "lit_110_8", "C", "", "Pagina: ");
				report.adicionaCampo(119, 5, "nroPagina", "S", "Z.ZZ9", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 3);
			{
				report.adicionaCampo(1, 60, "lit_1_60", "C", "", "* STI- SUBGERENCIA DE TECNOLOGIA DA INFORMCAO - VIVA CIDADAO");
				report.adicionaCampo(110, 8, "lit_110_8", "C", "", "Data..: ");
				report.adicionaCampo(119, 10, "dataCorrente", "S", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(4, 1);
			{
				report.adicionaCampo(1, 30, "lit_1_30", "C", "", "* INSTITUICAO DE IDENTIFICACAO");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(5, 5);
			{
				report.adicionaCampo(1, 36, "lit_1_36", "C", "", "* ATESTADOS DE ANTECEDENTES EMITIDOS");
				report.adicionaCampo(10, 9, "lit_10_9", "C", "", "PERIODO: ");
				report.adicionaCampo(20, 8, "datini", "N", "99/99/9999", "");
				report.adicionaCampo(29, 2, "lit_29_2", "C", "", " -");
				report.adicionaCampo(32, 8, "Datfim", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(6, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(7, 1);
			{
				report.adicionaCampo(1, 36, "lit_1_36", "C", "", "*** TOTAL DE ATESTADOS EMITIDOS  EM:");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(8, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(1, 1);
			{
				report.adicionaCampo(1, 1, "lit_1_1", "C", "", "-");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(2, 2);
			{
				report.adicionaCampo(1, 18, "lit_1_18", "C", "", "*** TOTAL GERAL = ");
				report.adicionaCampo(20, 4, "Jcont1", "N", "ZZZ9", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(3, "D");
		{
			report.setNumeroLinhaRel(1, 3);
			{
				report.adicionaCampo(1, 8, "dtini", "N", "99/99/9999", "");
				report.adicionaCampo(10, 3, "lit_10_3", "C", "", " = ");
				report.adicionaCampo(14, 4, "Jcont", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
		}
		setDataCorrente(dataCorrente);
	}

	public boolean validar() {
		// validar os campos recebidos da tela
		return true;
	}

	public String getDtini() {
		return dtini;
	}

	public void setDtini(String dtini) throws ParseException {
		this.dtini = dtini;
		report.adicionaValorReport("dtini", dtini);
	}

	public int getJcont() {
		return jcont;
	}

	public void setJcont(int jcont) throws ParseException {
		this.jcont = jcont;
		report.adicionaValorReport("Jcont", jcont);
	}

	public int getJcont1() {
		return jcont1;
	}

	public void setJcont1(int jcont1) throws ParseException {
		this.jcont1 = jcont1;
		report.adicionaValorReport("Jcont1", jcont1);
	}

	public String getDatini() {
		return datini;
	}

	public void setDatini(String datini) throws ParseException {
		this.datini = datini;
		report.adicionaValorReport("datini", datini);
	}

	public String getDatfim() {
		return datfim;
	}

	public void setDatfim(String datfim) throws ParseException {
		this.datfim = datfim;
		report.adicionaValorReport("Datfim", datfim);
	}

	public String getDataCorrente() {
		return dataCorrente;
	}

	public void setDataCorrente(String dataCorrente) throws ParseException {
		this.dataCorrente = dataCorrente;
		report.adicionaValorReport("dataCorrente", dataCorrente);
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		setNroPagina(String.valueOf(report.getPageNumber()));
		report.gravaRelatorio(report, nroRel, false);
	}

	public InputStreamDownload imprimir() throws FileNotFoundException, JRException {
		return report.imprimir();
	}

	public String getNroPagina() {
		return nroPagina;
	}

	public void setNroPagina(String nroPagina) throws ParseException {
		this.nroPagina = nroPagina;
		report.adicionaValorReport("nroPagina", nroPagina);
	}

}
